package com.leetcode.LC_MED;

import java.util.List;

public class LC139 {
    // 自己的思路，遇到特殊案例会挂掉
    public boolean wordBreak(String s, List<String> wordDict) {
        StringBuilder builder = new StringBuilder(s);
        for (String s1 : wordDict) {
            String[] split = builder.toString().split(s1);
            if (split.length == 0) {
                return true;
            } else {
                builder = new StringBuilder();
                for (String s2 : split) {
                    builder.append(s2);
                }
            }
        }
        return false;
    }

    // 大神思路
    public boolean wordBreak_2(String s, List<String> wordDict) {
        int length = s.length();
        boolean[] dp = new boolean[length + 1];
        dp[0] = true;
        for (int i = 1; i <= length; i++) {
            for (int j = 0; j < i; j++) {
                if (dp[j] && wordDict.contains(s.substring(j, i))) {
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[length];
    }

    public static void main(String[] args) {
        String[] split = "aaa".split("a");
        System.out.println(split.length);
        for (String s : split) {
            System.out.println(s);
        }
    }
}
